package com.rds.system.service.impl;

import com.rds.common.utils.DateUtils;
import com.rds.system.domain.RdaCommand;
import com.rds.system.mapper.RdaCommandMapper;
import com.rds.system.mapper.SysRoleMapper;
import com.rds.system.service.IRdaCommandService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * command命令Service业务层处理
 *
 * @author rds
 * @date 2021-04-19
 */
@Service
public class RdaCommandServiceImpl implements IRdaCommandService
{
    @Autowired
    private RdaCommandMapper rdaCommandMapper;

    @Autowired
    private SysRoleMapper sysRoleMapper;

    /**
     * 查询command命令
     *
     * @param id command命令ID
     * @return command命令
     */
    @Override
    public RdaCommand selectRdaCommandById(Long id)
    {
        return rdaCommandMapper.selectRdaCommandById(id);
    }

    /**
     * 查询command命令列表
     *
     * @param rdaCommand command命令
     * @return command命令
     */
    @Override
    public List<RdaCommand> selectRdaCommandList(RdaCommand rdaCommand)
    {
        List<RdaCommand> list=rdaCommandMapper.selectRdaCommandList(rdaCommand);
        for (RdaCommand command : list) {
            if(command.getRoleIds()!=null && !command.getRoleIds().equals("")){
                String[] ids = command.getRoleIds().split(",");
                command.setRoleIds(sysRoleMapper.selectRoleByIds(ids));
            }
        }
        return list;
    }

    /**
     * 根据名称查询列
     *
     * @param commandId
     * @return command命令
     */
    public List<RdaCommand> selectByCommandId(@Param("commandId")String[] commandId, @Param("roleIds")Set<String> roleIds, @Param("command")String command)
    {
        return rdaCommandMapper.selectByCommandId(commandId,roleIds,command);
    }

    /**
     * 根据Toolbar名称查询列
     *
     * @param configName
     * @return table列集合
     */
    public List<RdaCommand> selectByToolbar(@Param("configName")String configName,@Param("roleIds")Set<String> roleIds){
        return rdaCommandMapper.selectByToolbar(configName,roleIds);
    }
    /**
     * 根据portal区域id查询列
     *
     * @param fromid
     * @return table列集合
     */
    public List<RdaCommand> selectByPortal(Long fromid){
        return rdaCommandMapper.selectByPortal(fromid);
    }

    /**
     * 根据TreeMenu名称查询列
     *
     * @param configName
     * @return table列集合
     */
    public List<RdaCommand> selectByTreeMenu(String configName){
        return rdaCommandMapper.selectByTreeMenu(configName);
    }

    /**
     * 新增command命令
     *
     * @param rdaCommand command命令
     * @return 结果
     */
    @Override
    public int insertRdaCommand(RdaCommand rdaCommand)
    {
        rdaCommand.setCreateTime(DateUtils.getNowDate());
        return rdaCommandMapper.insertRdaCommand(rdaCommand);
    }

    /**
     * 修改command命令
     *
     * @param rdaCommand command命令
     * @return 结果
     */
    @Override
    public int updateRdaCommand(RdaCommand rdaCommand)
    {
        return rdaCommandMapper.updateRdaCommand(rdaCommand);
    }

    /**
     * 批量删除command命令
     *
     * @param ids 需要删除的command命令ID
     * @return 结果
     */
    @Override
    public int deleteRdaCommandByIds(Long[] ids)
    {
        return rdaCommandMapper.deleteRdaCommandByIds(ids);
    }

    /**
     * 删除command命令信息
     *
     * @param id command命令ID
     * @return 结果
     */
    @Override
    public int deleteRdaCommandById(Long id)
    {
        return rdaCommandMapper.deleteRdaCommandById(id);
    }
}
